package com.ruoyi.zsyh.controller.applet.after.factory;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.zsyh.domain.ZsyhServiceOrder;
import com.ruoyi.zsyh.domain.ZsyhServiceOrderApplymoney;
import com.ruoyi.zsyh.domain.ZsyhServiceOrderLog;
import com.ruoyi.zsyh.domain.ZsyhUserRepairstore;
import com.ruoyi.zsyh.service.IZsyhServiceOrderApplymoneyService;
import com.ruoyi.zsyh.service.IZsyhServiceOrderLogService;
import com.ruoyi.zsyh.service.IZsyhServiceOrderService;
import com.ruoyi.zsyh.service.IZsyhUserRepairstoreService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 服务订单 -- 配件单
 */
@Controller
@RequestMapping("/applet/zsyh/serviceOrderApplyMoneyFactory")
public class ZsyhServiceOrderApplyMoneyFactoryAppletController extends BaseController
{

    @Autowired
    private IZsyhServiceOrderApplymoneyService zsyhServiceOrderApplymoneyService;

    @Autowired
    private IZsyhUserRepairstoreService zsyhUserRepairstoreService;

    @Autowired
    private IZsyhServiceOrderLogService zsyhServiceOrderLogService;

    @Autowired
    private IZsyhServiceOrderService zsyhServiceOrderService;



    /**
     * 厂家 订单中心 获取费用单列表
     * @return
     * @throws Exception
     */
    @RequestMapping("/getFactoryApplyMoneyList")
    @ResponseBody
    public AjaxResult getFactoryApplyMoneyList(String factoryId, String applyMoneyId, String applyState, String orderState, String pageNum, String pageSize)throws Exception
    {

        ZsyhServiceOrderApplymoney applymoney = new ZsyhServiceOrderApplymoney();
        applymoney.setId(applyMoneyId);
        applymoney.setFactoryId(factoryId);
        applymoney.setApplyState(applyState);
        applymoney.setOrderState(orderState);
        List<ZsyhServiceOrderApplymoney> listSize = zsyhServiceOrderApplymoneyService.selectZsyhServiceOrderApplymoneyList(applymoney);
        int total = listSize.size();
        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        applymoney.setParams(map);
        List<ZsyhServiceOrderApplymoney> applymoneyList = zsyhServiceOrderApplymoneyService.selectZsyhServiceOrderApplymoneyList(applymoney);

        return success("成功", applymoneyList, total);
    }

    /**
     * 厂家 订单中心 费用单详情
     * @return
     * @throws Exception
     */
    @RequestMapping("/getFactoryApplyMoneyDetails")
    @ResponseBody
    public AjaxResult getFactoryApplyMoneyDetails(String applyId)throws Exception
    {
        ZsyhServiceOrderApplymoney applyMoney = zsyhServiceOrderApplymoneyService.selectZsyhServiceOrderApplymoneyById(applyId);
        return success("成功", applyMoney);
    }

    /**
     * 审核费用单
     * @param applyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/auditApplyMoneyOrder")
    @ResponseBody
    public AjaxResult auditApplyMoneyOrder(String applyId, String applyState, String applyRefuse)throws Exception
    {
        ZsyhServiceOrderApplymoney applyMoney = new ZsyhServiceOrderApplymoney();
        applyMoney.setId(applyId);
        applyMoney.setApplyState(applyState);
        applyMoney.setApplyRefuse(applyRefuse);
        zsyhServiceOrderApplymoneyService.updateZsyhServiceOrderApplymoney(applyMoney);
        return success("成功", applyMoney);
    }
}
